package com.morimoto.healthmeter;

import com.morimoto.healthmeter.calendar.InputCalendarView;
import com.morimoto.healthmeter.graph.GraphLayout;
import com.morimoto.rmlib.StorageManager;

import android.R.color;
import android.app.TabActivity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Display;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;

public class HealthMeterActivity extends TabActivity implements OnTabChangeListener {
	
	public static final String STORAGE_KEY = "healthmeter";
	
	private static final String TAB_TAG[] = {  
		"tag1", "tag2", 
	};  
	private static final String TAB_LABEL[] = {  
		"入力画面", "グラフ",  
	};  
		  
	private LinearLayout mTabCalendar = null;
	private LinearLayout mTabGraph = null;
	private int mScreenWidth = 0;
	private int mScreenHeight = 0;
	private StorageManager mStorage = null;
	
	private TabHost tabHost;
	private TabHost.TabSpec spec;
	
	private InputCalendarView mCalendarView = null;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        //init storage
        mStorage = new StorageManager(this, STORAGE_KEY);
        
        //Screen size
        WindowManager winMgr = (WindowManager)getSystemService(Context.WINDOW_SERVICE);
        Display disp = winMgr.getDefaultDisplay();
        mScreenWidth = disp.getWidth();
        mScreenHeight = disp.getHeight();
        
        // TabHost の取得  
        tabHost = getTabHost();
        // Tab が切り替わったときに呼ばれるコールバックを登録 
        tabHost.setOnTabChangedListener(this);
        
        // TabSpec の作成 
        spec = tabHost.newTabSpec(TAB_TAG[0]);
        // インジケーターの設定  
        spec.setIndicator(TAB_LABEL[0]);
        // Tab のコンテンツの設定  
        spec.setContent(R.id.content1);
        // TabHost に Tab を追加  
        tabHost.addTab(spec);

        // TabSpec の作成 
        spec = tabHost.newTabSpec(TAB_TAG[1]);
        // インジケーターの設定  
        spec.setIndicator(TAB_LABEL[1]);
        // Tab のコンテンツの設定  
        spec.setContent(R.id.content2);
        // TabHost に Tab を追加  
        tabHost.addTab(spec);
        
        //initialize calendar view 
        mTabCalendar = (LinearLayout) findViewById(R.id.content1);
        mCalendarView = new InputCalendarView(this);
        mCalendarView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, (int) (mScreenWidth * 1.1f)));
//        mCalendarView.setBackgroundColor(Color.rgb(255, 0, 255));
        mTabCalendar.addView(mCalendarView);
        mCalendarView.setOnClickListener(new OnClickListener() {
        	@Override
			public void onClick(View v) {
				
			}
		});
        

        //Tab 2
        mTabGraph = (LinearLayout) findViewById(R.id.content2);
        GraphLayout mGraphView = new GraphLayout(this);
        mTabGraph.addView(mGraphView);

//        LineChart lineChart = new LineChart();
//        Intent intent = lineChart.execute(this);
//        spec.setContent(intent);
        
        // 現在の Tab を設定  
        tabHost.setCurrentTab(0);  
    }

    @Override
	protected void onDestroy() {
		super.onDestroy();
		System.exit(RESULT_OK);
	}

	@Override
	protected void onRestart() {
		super.onRestart();
	}

	@Override
	protected void onResume() {
		super.onResume();
	}

	@Override
	protected void onStart() {
		super.onStart();
	}

	@Override
	protected void onStop() {
		super.onStop();
	}

	public int getScreenWidth() {
    	return mScreenWidth;
    }
    
    public int getScreenHeight() {
    	return mScreenHeight;
    }

    public StorageManager getStorage() {
    	return mStorage;
    }

	@Override
	public void onTabChanged(String tabId) {
		
	}
}

